?><?
class rule extends cls_entity{

  var $id=-1;
  var $instance_id=0;
  var $user_id=0;
  var $aread=0;
  var $awrite=0;
  var $aadd=0;
  var $adelete=0;
  var $amove=0;

  function entity(){return "rule";}

  function load(&$array){$this->load_from_array($array);}

  function load_from_array(&$array){
    $this->id         =(int)$array["user_inst_id"];;
    $this->instance_id=(int)$array["instance_id"];
    $this->user_id    =(int)$array["user_id"];
    $this->aread      =(int)get_bool_value($array["user_inst_read"]);
    $this->awrite     =(int)get_bool_value($array["user_inst_write"]);
    $this->aadd       =(int)get_bool_value($array["user_inst_add"]);
    $this->amove      =(int)get_bool_value($array["user_inst_move"]);
    $this->adelete    =(int)get_bool_value($array["user_inst_delete"]);
  }

  function load_from_bd($id){$this->load(NextRow(ExecSQL("select * from user_inst where user_inst_id=$id")));}

  function save(){
    if(NextRow(ExecSQL("select * from user_inst where user_inst_id=$this->id"))){
      ExecSQL("update user_inst set 
                instance_id=$this->instance_id, 
                user_inst_read=$this->aread, 
                user_inst_write=$this->awrite, 
                user_inst_add=$this->aadd, 
                user_inst_move=$this->amove, 
                user_inst_delete=$this->adelete 
                where user_inst_id=$this->id");
    }else{
      ExecSQL("insert into user_inst (instance_id,user_id,user_inst_read,user_inst_write,user_inst_add,user_inst_move,user_inst_delete) 
                        values($this->instance_id,$this->user_id,$this->aread,$this->awrite,$this->aadd,$this->amove,$this->adelete)");
      $this->id=getLastId();
    }
    $users=&get_entity("cls_user");
    $users->changed();
    $root=&get_global("root");
    $root->changed();
  }

  function delete($id){ExecSQL("delete from user_inst where user_inst_id=$id");}
}
